package cn.sccl.dirms.security.service.impl;

import cn.sccl.dirms.security.model.RoleAndAuthority;
import cn.sccl.dirms.security.service.RoleAndAuthorityManager;
import cn.sccl.common.dao.BaseDAO;
import cn.sccl.common.service.impl.BaseManagerImpl;
import cn.sccl.dirms.security.dao.RoleAndAuthorityDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by 杨浩宇 on 2016-02-24.
 */
@Service
public class RoleAndAuthorityManagerImpl extends BaseManagerImpl<RoleAndAuthority> implements RoleAndAuthorityManager {

    @Autowired
    private RoleAndAuthorityDAO roleAndAuthorityDAO;

    public RoleAndAuthorityDAO getRoleAndAuthorityDAO() {
        return roleAndAuthorityDAO;
    }

    @Override
    public BaseDAO<RoleAndAuthority> getBaseDAO() {
        return getRoleAndAuthorityDAO();
    }

    @Override
    public List<RoleAndAuthority> findRoleAndAuthId(String id) {
        String sql = "select ra.id,ra.authority_id,ra.role_id\n" +
                "    from   t_sec_roles_authorities      ra\n" +
                " where  ra.role_id = ?\n" +
                "   and  ra.delete_flag = 0";
        List<RoleAndAuthority> roleAndAuthoritiesList = getDataBase().query4Model(sql, RoleAndAuthority.class, new Object[]{id});
        return roleAndAuthoritiesList;
    }
}